home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / formats / urt / toolkit.doc < prev    next >
Text File  |  1994-10-02  |  30KB  |  730 lines

  1.  
  2.                             THE UTAH RASTER TOOLKIT
  3.  
  4.                                John W. Peterson
  5.                                  Rod G. Bogart
  6.                                       and
  7.                                Spencer W. Thomas
  8.  
  9. University of Utah, Department of Computer Science(Originally presented at the 
  10.                              Salt Lake City, Utah
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.                                    ABSTRACT
  20.  
  21.       The  Utah  Raster  Toolkit  is a set of programs for manipulating and
  22.     composing raster images.  These tools are based on the Unix concepts of
  23.     pipes  and  filters,  and operate on images in much the same way as the
  24.     standard Unix tools operate on  textual  data.    The  Toolkit  uses  a
  25.     special  run  length  encoding  (RLE)  format  for  storing  images and
  26.     interfacing between the various programs.  This reduces the disk  space
  27.     requirements  for  picture  storage  and  provides  a  standard  header
  28.     containing descriptive information about an image.  Some of  the  tools
  29.     are  able to work directly with the compressed picture data, increasing
  30.     their efficiency.  A library of C routines is provided for reading  and
  31.     writing the RLE image format, making the toolkit easy to extend.
  32.  
  33.       This paper describes the individual tools, and gives several examples
  34.     of their use and how they work together.  Additional topics that  arise
  35.     in  combining  images,  such  as how to combine color table information
  36.     from multiple sources, are also discussed.
  37.  
  38.  
  39.  
  40.  
  41.  
  42. 1. Introduction
  43.   Over the past several years, the University of Utah Computer Graphics Lab has
  44. developed several tools and techniques for generating, manipulating and storing
  45. images.  At first this was done in a somewhat haphazard manner - programs would
  46. generate  and  store  images  in various formats (often dependent on particular
  47. hardware) and data was often  not  easily  interchanged  between  them.    More
  48. recently, some effort has been made to standardize the image format, develop an
  49. organized set of tools for operating on the images, and  develop  a  subroutine
  50. library  to  make  extending this set of tools easier.  This paper is about the
  51. result of this effort, which we call the Utah Raster Toolkit.  Using  a  single
  52. efficient  image  format,  the  toolkit  provides  a  number  of  programs  for
  53. performing common operations  on  images.    These  are  in  turn  based  on  a
  54. subroutine library for reading and writing the images.
  55.  
  56. 2. Origins
  57.   The  idea for the toolkit arose while we were developing an image compositor.
  58. The compositor (described in  detail  in  section  4.1)  allows  images  to  be
  59. combined  in  various  ways.   We found that a number of simple and independent
  60. operations were frequently needed before images could be composited together.
  61.  
  62.   With the common image format, the subroutine library for manipulating it, and
  63. the  need  for  a number of independent tools, the idea of a "toolkit" of image
  64. manipulating programs arose.  These tools are combined using  the  Unix  shell,
  65. operating  on  images  much  like the standard Unix programs operate on textual
  66. data.  For example, a Unix user would probably use the sequence of commands:  
  67.  
  68.             cat /etc/passwd | grep Smith | sort -t: +4.0 | lpr
  69.  
  70. to print a sorted list of all users named "Smith" in the system password  file.
  71. Similarly, the Raster Toolkit user might do something like:  
  72.  
  73.             cat image.rle | avg4 | repos -p 0 200 | getfb
  74.  
  75. to  downfilter  an  image  and place it on top of the frame buffer screen.  The
  76. idea is similar to  a  method  developed  by  Duff [3]  for  three  dimensional
  77. rendering.
  78.  
  79. 3. The RLE format
  80.   The  basis  of  all  of these tools is a Run Length Encoded image format [8].
  81. This format is designed to provide an efficient, device  independent  means  of
  82. storing  multi-level  raster  images.    It is not designed for binary (bitmap)
  83. images.  It is built on several basic concepts.  The  central  concept  is  the
  84. channel.    A  channel  corresponds  to a single color, thus there are normally
  85. separate red, green and blue channels.  Up to 255 color channels are  available
  86. for  use;  one  channel  is reserved for coverage ("alpha") data.  Although the
  87. format supports  arbitrarily  deep  channels,  the  current  implementation  is
  88. restricted  to  8  bits  per channel.  An RLE file is treated as a byte stream,
  89. making it independent of host byte ordering.
  90.  
  91.   Image data is stored in an RLE file in a scanline form,  with  the  data  for
  92. each  channel of the scanline grouped together.  Runs of identical pixel values
  93. are compressed into a count and a  value.    However,  sequences  of  differing
  94. pixels  are  also  stored  efficiently  (i.e, not as a sequence of single pixel
  95. runs).
  96.  
  97.  
  98.  
  99. 3.1. The RLE header
  100.   The file header contains a large amount of information about the image.  This
  101. includes:
  102.  
  103.    - The size and position on the screen,
  104.  
  105.    - The  number  of  channels  saved  and  the number of bits per channel
  106.      (currently, only eight bits per channel is supported),
  107.  
  108.    - Several flags, indicating: how  the  background  should  be  handled,
  109.      whether  or  not an alpha channel was saved, if picture comments were
  110.      saved,
  111.  
  112.    - The size and number of channels in the color map, (if the  color  map
  113.      is supplied),
  114.  
  115.    - An optional background color,
  116.  
  117.    - An optional color map,
  118.  
  119.    - An  optional  set of comments.  The comment block contains any number
  120.      of null-terminated text strings.  These strings are conventionally of
  121.      the  form  "name=value",  allowing  for  easy  retrieval  of specific
  122.      information.
  123.  
  124.  
  125.  
  126. 3.2. The scanline data
  127.   The scanline is the basic unit that programs read and write.  It consists  of
  128. a  sequence  of operations, such as Run, SetChannel, and Pixels, describing the
  129. actual image.  An image is  stored  starting  at  the  lower  left  corner  and
  130. proceeding  upwards in order of increasing scanline number.  Each operation and
  131. its associated data takes up an even number of bytes, so  that  all  operations
  132. begin  on  a  16 bit boundary.  This makes the implementation more efficient on
  133. many architectures.
  134.  
  135.   Each operation is identified by an 8 bit opcode, and may  have  one  or  more
  136. operands.    Single  operand  operations  fit  into a single 16 bit word if the
  137. operand value is less than 256.  So that operand values are not limited to  the
  138. range  0..255,  each  operation has a long variant, in which the byte following
  139. the opcode is ignored and the following word is taken as  a  16  bit  quantity.
  140. The  long  variant  of  an  opcode  is indicated by setting the bit 0x40 in the
  141. opcode (this allows for 64 opcodes, of which 6 have been used so far.)
  142.  
  143.   The current set of opcodes include:
  144.  
  145.   SkipLines    Increment the scanline number by the operand value,  terminating
  146.                the current scanline.
  147.  
  148.   SetColor     Set the current channel to the operand value.
  149.  
  150.   SkipPixels   Skip  over  pixels in the current scanline.  Pixels skipped will
  151.                be left in the background color.
  152.  
  153.   PixelData    Following this opcode is a sequence of pixel values.  The length
  154.                of the sequence is given by the operand value.
  155.  
  156.   Run          This  is  the only two operand opcode.  The first operand is the
  157.                length (N) of the run.  The second operand is the  pixel  value,
  158.                followed  by  a  filler  byte  if necessary(E.g., a 16 bit pixel
  159.                value would not need a filler byte.).  The next N pixels in  the
  160.                scanline are set to the given pixel value.
  161.  
  162.   EOF          This  opcode  has  no  operand, and indicates the end of the RLE
  163.                file.  It is provided so RLE files may be concatenated  together
  164.                and  still  be  correctly  interpreted.    It is not required, a
  165.                physical end of file also indicates the end of the RLE data.
  166.  
  167.  
  168.  
  169. 3.3. Subroutine Interface
  170.   Two similar subroutine interfaces are provided for reading and writing  files
  171. in  the  RLE format.  Both read or write a scanline worth of data at a time.  A
  172. simple "row" interface communicates in terms of arrays of pixel values.  It  is
  173. simple  to  use,  but  slower  than  the  "raw" interface, which uses arrays of
  174. "opcode" values as its communication medium.
  175.  
  176.   In both cases, the interface must be initialized by calling a setup function.
  177. The two types of calls may be interleaved; for example, in a rendering program,
  178. the background could be written using  the  "raw"  interface,  while  scanlines
  179. containing image data could be converted with the "row" interface.  The package
  180. allows multiple RLE streams to be open simultaneously, as is necessary for  use
  181. in  a  compositing  tool,  for  example.  All data relevant to a particular RLE
  182. stream is contained in a  "globals"  structure.    This  structure  essentially
  183. echoes  the information in the RLE header, along with current state information
  184. about the RLE stream.
  185.  
  186. 4. The tools
  187.  
  188.  
  189.  
  190. 4.1. The image compositor - Comp
  191.   Comp implements an image  compositor  based  on  the  compositing  algorithms
  192. presented  in [6].   The compositing operations are based on the presence of an
  193. alpha channel in the image.  This extra channel usually defines  a  mask  which
  194. represents  a  sort  of  a  cookie-cutter for the image.  This is the case when
  195. alpha is 255 (full coverage) for pixels inside the  shape,  zero  outside,  and
  196. between  zero  and 255 on the boundary.  When the compositor operates on images
  197. of the cookie-cutter style, the operations behave as follows:
  198.  
  199.   A over B (the default)
  200.                The  result  will  be  the union of the two image shapes, with A
  201.                obscuring B in the region of overlap.
  202.  
  203.   A atop B     The result shape is the same as image  B,  with  A  obscuring  B
  204.                where  the  image  shapes  overlap. (Note that this differs from
  205.                "over" because the portion of A outside the shape of B will  not
  206.                be in the result image.)
  207.  
  208.   A in B       The  result is simply the image A cut by the shape of B. None of
  209.                the image data of B will be in the result.
  210.  
  211.   A out B      The result image is image A with the shape of B cut out.
  212.  
  213.   A xor B      The result is the image data from both images  that  is  outside
  214.                the overlap region.  The overlap region will be blank.
  215.  
  216.   A plus B     The result is just the sum of the image data.  This operation is
  217.                actually independent of the alpha channels.
  218.  
  219.   The alpha channel can also represent a semi-transparent mask for  the  image.
  220. It would be similar to the cookie-cutter mask, except the interior of the shape
  221. would have alpha values that represent  partial  coverage;  e.g.  128  is  half
  222. coverage.   When one of the images to be composited is a semi-transparent mask,
  223. the following operations have useful results:
  224.  
  225.   Semi-transparent A over B
  226.                The  image  data  of  B  will  be  blended with that of A in the
  227.                semi-transparent overlap region.  The resulting alpha channel is
  228.                as transparent as that of image B.
  229.  
  230.   A in Semi-transparent B
  231.                The image data of A is scaled by the mask of B  in  the  overlap
  232.                region.    The alpha channel is the same as the semi-transparent
  233.                mask of B.
  234.  
  235.   If the picture to be composited doesn't have an alpha channel  present,  comp
  236. assumes  an alpha of 255 (i.e., full coverage) for non-background pixels and an
  237. alpha of zero for background pixels.
  238.  
  239.   Comp is able to take advantage of the size information  for  the  two  images
  240. being  composited.   For example, if a small picture is being composited over a
  241. large backdrop, the actual compositing arithmetic is only performed on a  small
  242. portion  of  the  image.   By looking at the image size in the RLE header, comp
  243. performs the compositing operation only where the images overlap.  For the rest
  244. of  the  image  the  backdrop  is  copied  (or  not  copied,  depending  on the
  245. compositing operation).  The "raw" RLE read and  write  routines  are  used  to
  246. perform  this  copy  operation,  thus  avoiding  the  cost  of  compressing and
  247. expanding the backdrop as well.
  248.  
  249.  
  250.  
  251. 4.2. Basic image composition - Repos and Crop
  252.   Repos and crop are the basic tools for positioning and arranging images to be
  253. fed  to the compositor.  Crop simply throws away all parts of the image falling
  254. outside the rectangle specified.   Repos  positions  an  image  to  a  specific
  255. location  on  the screen, or moves it by an incremental amount.  Repos does not
  256. have to  modify  any  of  the  image  data,  it  simply  changes  the  position
  257. specification  in  the  RLE  header.  In order to simplify the code, the Raster
  258. Toolkit does not allow negative pixel coordinates in images.
  259.  
  260.  
  261.  
  262. 4.3. Changing image orientation and size - Flip, Fant and Avg4
  263.   Two tools exist for changing the orientation of an image on the screen.  Flip
  264. rotates  an  image  by 90 degrees right or left, turns an image upside down, or
  265. reverse it from right to left.  Fant rotates an image an  arbitrary  number  of
  266. degrees  from  -45  to 45.  In order to get rotation beyond -45 to 45, flip and
  267. fant can be combined, for example:  
  268.  
  269.             flip -r < upright.rle | fant -a 10 > rotated.rle
  270.  
  271. rotates an image 100 degrees.   Fant  is  also  able  to  scale  images  by  an
  272. arbitrary  amount  in X and Y. A common use for this is to stretch or shrink an
  273. image to correct for the aspect ratio of a particular frame buffer. Many  frame
  274. buffers  designed  for  use  with  standard video hardware display a picture of
  275. 512x480 pixels on a screen with the proportions 4:3, resulting  in  an  overall
  276. pixel  aspect  ratio  of 6:5.  If the picture kloo.rle is digitized or computed
  277. assuming a 1:1 aspect ratio (square pixels), the command:  
  278.  
  279.             cat kloo.rle | fant -s 1.0 1.2 | getfb
  280.  
  281. correctly displays the image on a frame buffer with a 6:5 aspect ratio.    Fant
  282. is  implemented  using  a  two-pass  subpixel  sampling  algorithm [4].    This
  283. algorithm performs the spatial transform (rotate and/or scale) first on row  by
  284. row  basis,  then  on  a column by column basis.  Because the transformation is
  285. done on a subpixel level, fant does not introduce aliasing artifacts  into  the
  286. image.
  287.  
  288.   Avg4  downfilters  an  RLE image into a resulting image of 1/4th the size, by
  289. simply averaging four pixel values in the input image to produce a single pixel
  290. in  the  output.  If the original image does not contain an alpha channel, avg4
  291. creates one by counting the number of non-zero pixels in  each  group  of  four
  292. input  pixels and using the count to produce a coverage value.  While the alpha
  293. channel produced this way is crude (only four levels of coverage) it is  enough
  294. to  make  a  noticeable improvement in the edges of composited images.  One use
  295. for avg4 is to provide anti-aliasing for rendering  programs  that  perform  no
  296. anti-aliasing  of  their own.  For example, suppose huge.rle is a 4k x 4k pixel
  297. image rendered without anti aliasing and without an alpha channel.    Executing
  298. the commands:  
  299.  
  300.             cat huge.rle | avg4 | avg4 | avg4 > small.rle
  301.  
  302. produces  an  image  small.rle  with  64  (8x8)  samples per pixel and an alpha
  303. channel with smooth edges.
  304.  
  305.   Images generated from this approach are as good as those produced  by  direct
  306. anti-aliasing  algorithms  such  as  the  A-buffer [2].    However,  a properly
  307. implemented A-buffer renderer produces images  nearly  an  order  of  magnitude
  308. faster.
  309.  
  310.  
  311.  
  312. 4.4. Color map manipulation - Ldmap and Applymap
  313.   As mentioned previously, RLE files may optionally contain a color map for the
  314. image.  Ldmap is used to create or modify a  color  map  within  an  RLE  file.
  315. Ldmap  is  able  to  create  some standard color maps, such as linear maps with
  316. various ramps, or maps with various gamma corrections.  Color maps may also  be
  317. read from a simple text file format, or taken from other RLE files.  Ldmap also
  318. performs map composition, where one color map is used  as  in  index  into  the
  319. other.    An  example  use  for this is to apply a gamma correction to an image
  320. already having a non-linear map.
  321.  
  322.   Applymap applies the color map in an rle file to  the  pixel  values  in  the
  323. file.  For example, if the color map in kloo.rle contained a color map with the
  324. entries (for the red channel):
  325.  
  326.     Index   Red color map
  327.         0:      5
  328.         1:      7
  329.         2:      9
  330.  
  331.   Then a (red channel) pixel value of zero would be displayed with an intensity
  332. of  five  (assuming  the display program used the color map in kloo.rle).  When
  333. kloo.rle is passed through applymap, 
  334.  
  335.             cat kloo.rle | applymap > kloo2.rle
  336.  
  337. pixels that had a value of zero in  kloo.rle  now  have  a  value  of  five  in
  338. kloo2.rle,  pixel  values  of one would now be seven, etc.  When displaying the
  339. images on a frame buffer, kloo2.rle appears the same with a linear  map  loaded
  340. as kloo.rle does with its special color map loaded.
  341.  
  342.   One use for these tools is merging images with different compensation tables.
  343. For example, suppose image gam.rle was computed so that  it  requires  a  gamma
  344. corrected  color table (stored in the RLE file) to be loaded to look correct on
  345. a particular monitor, and image lin.rle was computed with the gamma  correction
  346. already taken into consideration (so it looks correct with a linear color table
  347. loaded).  If these two images  are  composited  together  without  taking  into
  348. consideration  these  differences,  the  results  aren't  correct  (part of the
  349. resulting image is either too dim or washed out).  However, we can use applymap
  350. to "normalize" the two images to using a linear map with:  
  351.  
  352.     cat gam.rle | applymap | comp - lin.rle | ldmap -l > result.rle
  353.  
  354.  
  355.  
  356. 4.5.  Generating backgrounds
  357.   Unlike  most  of  the  toolkit programs which act as filters, background just
  358. produces output.  Background  either  produces  a  simple  flat  field,  or  it
  359. produces a field with pixel intensities ramped in the vertical direction.  Most
  360. often background is used simply to provide a colored  backdrop  for  an  image.
  361. Background  is  another  example of a program that takes advantage of the "raw"
  362. RLE facilities.  Rather than generating the  scanlines  and  compressing  them,
  363. background simply generates the opcodes required to produce each scanline.
  364.  
  365.  
  366.  
  367. 4.6.  Converting full RGB images to eight bits - to8 and tobw
  368.   Although  most  of  the  time  we  prefer  to work with full 24 bit per pixel
  369. images, (32 bits with alpha) we often need the images  represented  with  eight
  370. bits  per pixel.  Many inexpensive frame buffers (such as the AED 512) and many
  371. personal color workstations  (VaxStation  GPX,  Color  Apollos  and  Suns)  are
  372. equipped with eight bit displays.
  373.  
  374.   To8 converts a 24 bit image to an eight bit image by applying a dither matrix
  375. to the pixels.  This basically trades spatial resolution for color  resolution.
  376. The  resulting  image  has  eight  bits  of data per pixel, and also contains a
  377. special color map for displaying the dithered image (since most eight bit frame
  378. buffers still use 24 bit wide color table entries).
  379.  
  380.   Tobw  converts a picture from 24 bits of red, green, and blue to an eight bit
  381. gray level image.  It uses the standard television YIQ transformation of
  382.  
  383.     graylevel#=#0.35#*#red#+#0.55#*#green#+#0.10#*#blue.
  384.  
  385. These images are often preferred when displaying the  image  on  an  eight  bit
  386. frame buffer and shading information is more important than color.
  387.  
  388. 5.  Interfacing to the RLE toolkit
  389.   In  order  to  display  RLE  images,  a  number  of programs are provided for
  390. displaying the pictures on various devices.  These display  programs  all  read
  391. from  standard  input,  so  they  are  conveniently used as the end of a raster
  392. toolkit pipeline.  The original display program, getfb, displays images on  our
  393. ancient  Grinnell  GMR-27  frame buffer.  Many display programs have since been
  394. developed:
  395.  
  396.   getcx        displays images on a Chromatics CX1500
  397.  
  398.   getiris      displays an image on an Iris workstation (via ethernet)
  399.  
  400.   getX         for the X window system
  401.  
  402.   getap        for the Apollo display manager
  403.  
  404.   gethp        for the Hewlett-Packard Series 300 workstation color display
  405.  
  406.   rletops      converts an RLE file to gray-level PostScript output(Rletops was
  407.                used to produce the figures in this paper.)
  408.  
  409.   The  getX,  getap  and  gethp  programs  automatically  perform the dithering
  410. required to convert a 24 bit RLE image to eight bits (for color nodes)  or  one
  411. bit  (for  bitmapped  workstations).  Since all of these workstations have high
  412. resolution  (1Kx1K)  displays,  the  trade  of  spatial  resolution  for  color
  413. resolution  produces  very  acceptable results.  Even on bitmapped displays the
  414. image quality is good enough to get a reasonable idea of an image's appearance.
  415.  
  416.   Two programs, painttorle and rletopaint  are  supplied  to  convert  MacPaint
  417. images  to  RLE  files.    This  offers  a  simple  way  to add text or graphic
  418. annotation to an RLE image (although the resolution is somewhat low).
  419.  
  420. 6.  Examples
  421.   A typical use for the toolkit is to take an image generated with a  rendering
  422. program, add a background to it, and display the result on a frame buffer:  
  423.  
  424.     rlebg 250 250 250 -v | comp image.rle - | getfb
  425.  
  426.   What follows are some more elaborate applications:
  427.  
  428.  
  429.  
  430. 6.1.  Making fake shadows
  431.   In  this  exercise  we  take  the  dart  (Figure  6-1a) and stick it into the
  432. infamous mandrill, making a nice (but completely fake) shadow along the way.
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.                             pics/dart_and_strtch.ps
  453.  
  454.      Figure 6-1:   a: Original dart image. b: Rotated and stretched dart.
  455.  
  456.   First the image of the dart is rotated by 90 degrees (using  rleflip  -l  and
  457. then  stretched  in the X direction (using fant -s 1.3 1.0) to another image we
  458. can use as  a  shadow  template,  figure  6-1b.    Then  we  take  this  image,
  459. dart_stretch_rot.rle, and do:  
  460.  
  461.     rlebg 0 0 0 175 \
  462.        | comp -o in - dart_stretch_rot.rle > dart_shadow.rle
  463.  
  464.   This  operation  uses the stretched dart as a cookie-cutter, and the shape is
  465. cut out of a black image, with a coverage mask (alpha channel) of  175.    Thus
  466. when we composite the shadow (figure 6-2a) over the mandrill image, it lets 32%
  467. of the mandrill through ((255 - 175) / 255 = 32%) with the rest being black.
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.                         pics/dart_shadow_and_monkey.ps
  488.  
  489.        Figure 6-2:   a: Dart shadow mask. b: Resulting skewered baboon.
  490.  
  491.   Now all we have left to do is to composite the dart and the shadow  over  the
  492. mandrill  image,  and  the result is figure 6-2b.  Note that since the original
  493. dart image was properly anti-aliased, no aliasing artifacts were introduced  in
  494. the final image.
  495.  
  496.  
  497.  
  498. 6.2.  Cutting holes
  499.   In  this example we start out out with a single bullet hole, created with the
  500. same modelling package that produced the dart.(The bullet hole was modeled with
  501. cubic  B-splines.    Normal  people  probably would have painted something like
  502. this...)  First the hole (which originally filled the screen)  is  downfiltered
  503. to a small size, with 
  504.  
  505.     avg4 < big_hole.rle | avg4 | avg4 > smallhole.rle
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                       pics/bullet_holes_and_shot_turb.ps
  526.  
  527.       Figure 6-3:   a: A set of bullet holes. b: A shot-up turbine blade.
  528.  
  529.   Now  by  invoking  repos  and  comp several times in a row, a set of shots is
  530. built up (Figure 6-3a)
  531.  
  532.   To shoot up the turbine blade, the atop operator of comp is used.  This works
  533. much  like  over,  except  the  bullet holes outside of the turbine blade don't
  534. appear in the resulting image (Figure 6-3b) Note how the  top  left  corner  is
  535. just grazed.
  536.  
  537.   But  there's still one catch.  Suppose we want to display the shot-up turbine
  538. blade over a background of some sort.  We want to be see the background through
  539. the  holes.  To do this we come up with another mask to cut away the centers of
  540. the bullet holes already on the turbine  blade  so  we  can  see  through  them
  541. (Figure 6-4a).
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.                        pics/center_masks_and_fin_turb.ps
  562.  
  563.          Figure 6-4:   a: Cut-away masks for the bullet hole centers.
  564.                                  b: Finished turbine blade
  565.  
  566. Now we can see through the blade (Figure 6-4b).
  567.  
  568.  
  569.  
  570. 6.3.  Integrating digitized data
  571.   In  this  example, we take a raw digitized negative and turn it into a useful
  572. frame buffer image.  Figure 6-5a shows the original  image  from  the  scanner.
  573. First the image is cropped to remove the excess digitized portion, then rotated
  574. into place with flip -r, resulting in Figure 6-5b.
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.                           pics/scanned_and_cropped.ps
  595.  
  596.   Figure 6-5:   a: The raw digitized negative.  b: Cropped and rotated image
  597.  
  598.   To get the image to appear as a positive on  the  frame  buffer,  a  negative
  599. linear  color map (stored as text file) is loaded, then this is composed with a
  600. gamma correction map of 2.2,  and  finally  applied  to  the  pixels  with  the
  601. command:  
  602.  
  603.     ldmap -f neg.cmap < neg_pahriah.rle | ldmap -a -g 2.2 \
  604.        | applymap > pahriah.rle
  605.  
  606. The result, Figure 6-6 now appears correct with a linear color map loaded.
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.                              pics/pahriah_final.ps
  627.  
  628.             Figure 6-6:   Final image of the old Pahriah ghost town
  629.  
  630. 7. Future Work
  631.   Needless  to  say,  a  project  such  as  the Raster Toolkit is open ended in
  632. nature, and new tools are easily added.  For example, most of the tools we have
  633. developed  to date deal with image synthesis and composition, primarily because
  634. that is our research orientation.  Additional tools could be  added  to  assist
  635. work  in  areas  such as vision research or image processing (for examples, see
  636.  [1, 7]).
  637.  
  638.   Another interesting application would be a visual "shell"  for  invoking  the
  639. tools.    Currently, arguments to programs like crop and repos are specified by
  640. tediously finding the numbers with the frame buffer cursor and then typing them
  641. into  a  shell.  The visual shell would allow the various toolkit operations to
  642. be interactively selected from a menu.    Such  a  shell  could  probably  work
  643. directly  with an existing workstation window system such as X [5] to provide a
  644. friendly environment for using the toolkit.
  645.  
  646. 8. Conclusions
  647.   The Raster Toolkit provides a flexible, simple and  easily  extended  set  of
  648. tools  for  anybody  working  with images in a Unix-based environment.  We have
  649. ported the toolkit to a wide variety of  Unix  systems,  including  Gould  UTX,
  650. HP-UX, Sun Unix, Apollo Domain/IX, 4.2 and 4.3 BSD, etc.  The common interfaces
  651. of the RLE format and the subroutine library make  it  easy  to  interface  the
  652. toolkit to a wide variety of image sources and displays.
  653.  
  654. 9. Acknowledgments
  655.   This   work  was  supported  in  part  by  the  National  Science  Foundation
  656. (DCR-8203692 and DCR-8121750), the Defense Advanced  Research  Projects  Agency
  657. (DAAK11-84-K-0017), the Army Research Office (DAAG29-81-K-0111), and the Office
  658. of Naval Research (N00014-82-K-0351).  All opinions, findings,  conclusions  or
  659. recommendations  expressed in this document are those of the authors and do not
  660. necessarily reflect the views of the sponsoring agencies.
  661.  
  662.                                   REFERENCES
  663.  
  664.  
  665. [1]   Burt, Peter J, and Adelson, Edward H.
  666.       A Multiresolution Spline With Application to Image Mosaics.
  667.       ACM Transactions on Graphics 2(4):217-236, October, 1983.
  668.  
  669.  
  670. [2]   Carpenter, Loren.
  671.       The A-Buffer, An Antialiased Hidden Surface Method.
  672.       Computer Graphics 18(3):103, July, 1984.
  673.       Proceedings of SIGGRAPH 84.
  674.  
  675.  
  676. [3]   Duff, Tom.
  677.       Compositing 3-D Rendered Images.
  678.       Computer Graphics 19(3):41, July, 1985.
  679.       Proceedings of SIGGRAPH 85.
  680.  
  681.  
  682. [4]   Fant, Karl M.
  683.       A Nonaliasing, Real-Time, Spatial Transform.
  684.       IEEE Computer Graphics and Applications 6(1):71, January, 1986.
  685.  
  686.  
  687. [5]   Gettys, Jim, Newman, Ron, and Fera, Tony D.
  688.       Xlib - C Language X Interface, Protocol Version 10.
  689.       Technical Report, MIT Project Athena, January, 1986.
  690.  
  691.  
  692. [6]   Porter, Thomas and Duff, Tom.
  693.       Compositing Digital Images.
  694.       Computer Graphics 18(3):253, July, 1984.
  695.       Proceedings of SIGGRAPH 84.
  696.  
  697.  
  698. [7]   Stockham, Thomas G.
  699.       Image Processing in the Context of a Visual Model.
  700.       Proceedings of the IEEE 60(7):828-842, July, 1972.
  701.  
  702.  
  703. [8]   Thomas, Spencer W.
  704.       Design of the Utah RLE Format.
  705.       Technical Report 86-15, Alpha_1 Project, CS Department, University of
  706.          Utah, November, 1986.
  707.  
  708.                                Table of Contents
  709. 1. Introduction                                                               0
  710. 2. Origins                                                                    0
  711. 3. The RLE format                                                             0
  712.      3.1. The RLE header                                                      0
  713.      3.2. The scanline data                                                   0
  714.      3.3. Subroutine Interface                                                0
  715. 4. The tools                                                                  0
  716.      4.1. The image compositor - Comp                                         0
  717.      4.2. Basic image composition - Repos and Crop                            1
  718.      4.3. Changing image orientation and size - Flip, Fant and Avg4           1
  719.      4.4. Color map manipulation - Ldmap and Applymap                         1
  720.      4.5.  Generating backgrounds                                             1
  721.      4.6.  Converting full RGB images to eight bits - to8 and tobw            1
  722. 5.  Interfacing to the RLE toolkit                                            1
  723. 6.  Examples                                                                  2
  724.      6.1.  Making fake shadows                                                2
  725.      6.2.  Cutting holes                                                      2
  726.      6.3.  Integrating digitized data                                         2
  727. 7. Future Work                                                                3
  728. 8. Conclusions                                                                3
  729. 9. Acknowledgments                                                            4
  730.